#!/bin/sh

#
# This file is released under the terms of the Artistic License.
# Please see the file LICENSE, included in this package, for details.
#
# Copyright (C) 2002-2010 Mark Wong & Open Source Development Lab, Inc.
#               2006 Rilson Nascimento
#

if [ -z "${DBT5DBNAME}" ]; then
	echo "DBT5DBNAME not defined."
	exit 1
fi

while getopts "p:" OPT; do
	case ${OPT} in
	p)
		PORT=${OPTARG}
		;;
	esac
done

if [ ! "x${PORT}" = "x" ]; then
	PORTARG="-p ${PORT}"
fi

PSQL="psql -d ${DBT5DBNAME} ${PORTARG} -q -t"

# Load tables
echo -n account_permission
${PSQL} -c "select count(*) from ACCOUNT_PERMISSION" 
echo -n customer
${PSQL} -c "select count(*) from CUSTOMER" 
echo -n customer_account
${PSQL} -c "select count(*) from CUSTOMER_ACCOUNT" 
echo -n customer_taxrate
${PSQL} -c "select count(*) from CUSTOMER_TAXRATE" 
echo -n holding
${PSQL} -c "select count(*) from HOLDING" 
echo -n holding_history
${PSQL} -c "select count(*) from HOLDING_HISTORY" 
echo -n holding_summary
${PSQL} -c "select count(*) from HOLDING_SUMMARY" 
echo -n watch_item
${PSQL} -c "select count(*) from WATCH_ITEM" 
echo -n watch_list
${PSQL} -c "select count(*) from WATCH_LIST" 
echo -n broker
${PSQL} -c "select count(*) from BROKER" 
echo -n cash_transaction
${PSQL} -c "select count(*) from CASH_TRANSACTION" 
echo -n charge
${PSQL} -c "select count(*) from CHARGE" 
echo -n commission_rate
${PSQL} -c "select count(*) from COMMISSION_RATE" 
echo -n settlement
${PSQL} -c "select count(*) from SETTLEMENT" 
echo -n trade
${PSQL} -c "select count(*) from TRADE" 
echo -n trade_history
${PSQL} -c "select count(*) from TRADE_HISTORY" 
echo -n trade_request
${PSQL} -c "select count(*) from TRADE_REQUEST" 
echo -n trade_type
${PSQL} -c "select count(*) from TRADE_TYPE" 
echo -n company
${PSQL} -c "select count(*) from COMPANY" 
echo -n company_competitor
${PSQL} -c "select count(*) from COMPANY_COMPETITOR" 
echo -n daily_market
${PSQL} -c "select count(*) from DAILY_MARKET" 
echo -n exchange
${PSQL} -c "select count(*) from EXCHANGE" 
echo -n financial
${PSQL} -c "select count(*) from FINANCIAL" 
echo -n industry
${PSQL} -c "select count(*) from INDUSTRY" 
echo -n last_trade
${PSQL} -c "select count(*) from LAST_TRADE" 
echo -n news_item
${PSQL} -c "select count(*) from NEWS_ITEM" 
echo -n news_xref
${PSQL} -c "select count(*) from NEWS_XREF" 
echo -n sector
${PSQL} -c "select count(*) from SECTOR" 
echo -n security
${PSQL} -c "select count(*) from SECURITY" 
echo -n address
${PSQL} -c "select count(*) from ADDRESS" 
echo -n status_type
${PSQL} -c "select count(*) from STATUS_TYPE" 
echo -n taxrate
${PSQL} -c "select count(*) from TAXRATE" 
echo -n zip_code
${PSQL} -c "select count(*) from ZIP_CODE" 
